//tablemodel.h
#ifndef MYTABLEMODEL_H
#define MYTABLEMODEL_H

#include <QSqlQueryModel>

#include <QSqlQuery>

class myTableModel:public QSqlQueryModel
{
    Q_OBJECT
    Q_PROPERTY(QString m_tableName READ tableName WRITE setTableName NOTIFY tableNameChanged)
    Q_PROPERTY(QString startTime READ startTime WRITE setStartTime NOTIFY startTimeChanged)
    Q_PROPERTY(QString endTime READ endTime WRITE setEndTime NOTIFY endTimeChanged)
    Q_PROPERTY(int currentPage READ currentPage WRITE setCurrentPage NOTIFY currentPageChanged)
public:
    myTableModel(QSqlQueryModel* parent = nullptr);
    virtual ~myTableModel();
    Q_INVOKABLE QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
    QVariant data(const QModelIndex &index, int role) const override;
    QHash<int, QByteArray> roleNames() const override;
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    int columnCount(const QModelIndex &parent = QModelIndex()) const override;

    QString tableName() const;
    void setTableName(const QString _tableName);
    QString startTime();
    void setStartTime(const QString startTime);
    QString endTime();
    void setEndTime(const QString endTime);

    int currentPage();
    void setCurrentPage(int currentPage);
    void refresh();
signals:
    void tableNameChanged();
    void startTimeChanged(QString startTime);
    void endTimeChanged(QString endTime);
    void currentPageChanged(int currentPage);
public slots:
    void slotTimeChanged(QString startTime, QString endTime);
    void slotStartTimeChanged(QString startTime);
    void slotEndTimeChanged(QString endTime);
    void slotCurrentPageChanged(int currentPage);
    int totalCount();
    //static void slotParaChanged(QString startTime, QString endTime, int currentPage);
private:
    QString m_tableName;
    QVector<QString> m_tableTitle;
    QSqlQuery* m_query;
    QHash<int, QByteArray> m_roleNames;
    QString m_startTime = "";
    QString m_endTime = "";
    QString queryser;
    QSqlDatabase m_db;
    int m_currentPage=-1;
    //static void paraChanged(QString startTime, QString endTime, int currentPage, myTableModel& myTableModel);
};

#endif // MYTABLEMODEL_H
